package com.wg.net.operations.base;

import cn.hutool.core.date.TimeInterval;
import com.wg.core.io.IBinaryReader;
import com.wg.core.io.IBinaryWriter;
import com.wg.core.io.IBinaryWritable;

public class S2SOperationResponse extends OperationResponse {
    private final TimeInterval handleInterval = new TimeInterval(true);

    private int id;

    public S2SOperationResponse() {
    }

    public S2SOperationResponse(S2SOperationRequest request) {
        super(request.getOpCode());
        this.id = request.getId();
    }

    public S2SOperationResponse(S2SOperationRequest request, byte[] buffer) {
        super(request.getOpCode(), buffer);
        this.id = request.getId();
    }

    public S2SOperationResponse(S2SOperationRequest request, IBinaryWritable contract) {
        super(request.getOpCode(), contract.toBytes());
        this.id = request.getId();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public TimeInterval getHandleInterval() {
        return handleInterval;
    }

    @Override
    public void read(IBinaryReader reader) {
        id = reader.readInt();
        super.read(reader);
    }

    @Override
    public void write(IBinaryWriter writer) {
        writer.writeInt(id);
        super.write(writer);
    }

    @Override
    public String toString() {
        return "responseId=" + id + ", responseCode=" + opCode + ", returnCode=" + returnCode + ", msg='" + debugMsg + '\'';
    }
}
